<?php

namespace App\Models;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements JWTSubject    # 这里别忘了加
{
	use SoftDeletes;

	protected $table = 'user';
	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = [
		'username', 'email', 'password','tel','thumb','nick_name','wx_username','pay_password','wx_openid',
        'pid_one','pid_two','pid_three','is_sale_man','proxy_level'
	];

	/**
	 * The attributes that should be hidden for arrays.
	 *
	 * @var array
	 */
	protected $hidden = [
		'password', 'remember_token',
	];

	/**
	 * The attributes that should be cast to native types.
	 *
	 * @var array
	 */
	protected $casts = [
		'email_verified_at' => 'datetime',
	];


	//定义一对一用户和用户信息关联
	public function user_info()
	{
		return $this->hasOne(UserInfo::class,'user_id','id');
	}

	/**
	 * 用户评论一对多
	 * User: Clannad ~ ☆
	 * DateTime: 2019/11/2 14:49
	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
	 */
	public function comment()
	{
		return $this->hasMany(Comment::class,'user_id','id');
	}


	/**
	 * Get the identifier that will be stored in the subject claim of the JWT.
	 * 获取将存储在JWT主题声明中的标识符。
	 *
	 * @return mixed
	 */
	public function getJWTIdentifier()
	{
		return $this->getKey();
	}

	/**
	 * Return a key value array, containing any custom claims to be added to the JWT.
	 * 返回一个键值数组，包含要添加到JWT的任何自定义声明。
	 *
	 * @return array
	 */
	public function getJWTCustomClaims()
	{
		return [];
	}


	/**
	 * 用户地址 一对多
	 * User: Clannad ~ ☆
	 * DataTime：2019/11/18 0018 15:21
	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
	 */
	public function user_address()
	{
		return $this->hasMany(UserAddress::class,'user_id','id');
	}

	/**
	 * 用户订单
	 * User: Clannad ~ ☆
	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
	 */
	public function order()
	{
		return $this->hasMany(Order::class,'user_id','id');
	}

    /**
     * 用户优惠券
     * User: Clannad ~ ☆
     * DataTime：2020/5/6 0006 10:45
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function coupons()
	{
        return $this->hasMany(UserCoupons::class,'user_id','id');
	}
}
